const fs = require('fs');
const { ethers } = require('ethers');

// 读取 keystore 文件
const keystorePath = 'E:\\Geth\\data\\ethereum\\myDataDir\\keystore\\UTC--2024-09-05T09-23-15.697301900Z--738a31623a3d322dae28938135893fa12084a57d';
const keystore = fs.readFileSync(keystorePath, 'utf8');

// 获取运行脚本时的输入参数
const password = process.argv[2]; // 第一个参数是密码
if (!password) {
    console.error('Please provide a password as an argument.');
    process.exit(1);
}

// 解密 keystore 文件
ethers.Wallet.fromEncryptedJson(keystore, password).then(wallet => {
    console.log('Address:', wallet.address);
    console.log('Private Key:', wallet.privateKey);
}).catch(error => {
    console.error('Error decrypting keystore:', error);
});